import {defineStore} from "pinia";
import {messageType} from "@/types/component/widgets";
import useTaskStore from './task'
import {notification} from "ant-design-vue";

//消息队列
export default defineStore({
    id: 'message',
    state: () => ({
        messageList: [] as messageType[] | []
    }),
    actions: {
        PUSH_MESSAGE(message: messageType) {
            const taskStore = useTaskStore()
            let app = taskStore.GET_APP(message.name)
            if (app && message || message.name === 'system') {
                this.DO_NOTICE(message)
                // @ts-ignore
                this.messageList.push(message)
            }
        },
        DEL_MESSAGE(messageKey: string) {
            const idx = this.messageList.findIndex((el: messageType) => el.messageKey = messageKey)
            if (idx !== -1) {
                this.messageList.splice(idx, 1)
            }
        },
        DO_NOTICE(message: messageType) {
            notification.open({
                message: message.messageTitle,
                description: message.messageContent,
                duration: 2.5,
                icon: message.messageIcon,
                style: {
                    backgroundColor: "rgba(255, 255, 255, .8)",
                    backdropFilter: "blur(8px)",
                    borderRadius: "8px",
                    width: "360px",
                    fontWeight: 500,
                    color: "#5D666F",
                    zIndex: 97,
                },
                // @ts-ignore
                getContainer: () => document.getElementById('deskTop'),
                class: 'notification',
                key: message.messageKey,
                onClick: () => {
                    console.log('Notification Clicked!');
                },
            })
        }
    }
})